//  This file is part of Swordbible - http://www.swordwarrior.net
//  Copyright (C) 2003-2008 Manu Mital mital.manu@gmail.com

//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2, or (at your option)
//  any later version.

//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.

//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software Foundation,
//  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


// Devotional.cpp : implementation file
//

#include "stdafx.h"
#include "SwordBible.h"
#include "Devotional.h"
#include ".\devotional.h"


// CDevotional dialog

IMPLEMENT_DYNAMIC(CDevotional, CDialog)
CDevotional::CDevotional(CWnd* pParent /*=NULL*/)
	: CDialog(CDevotional::IDD, pParent)
	
{
	m_pMyPropSheet = NULL;
	isSheet = FALSE;					// initialize to false
}

CDevotional::~CDevotional()
{
	if(m_pMyPropSheet == NULL) return;

	 delete m_pMyPropSheet;
     m_pMyPropSheet = NULL;


}

void CDevotional::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	
}


BEGIN_MESSAGE_MAP(CDevotional, CDialog)
	ON_WM_SIZE()
END_MESSAGE_MAP()


// CDevotional message handlers

BOOL CDevotional::OnInitDialog()
{
	CDialog::OnInitDialog();


	//set the icon for the dialog
	SetIcon(::AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);

	CWnd* pwndPropSheetHolder = GetDlgItem(IDC_PLACEHOLDER_DEVOTIONAL);
	pwndPropSheetHolder->SetParent(this);

	CRect rect;
	GetWindowRect(rect);
	ScreenToClient(rect);
	pwndPropSheetHolder ->SetWindowPos(NULL,0,0,rect.Width(),
		rect.Height(),SWP_NOZORDER | SWP_NOACTIVATE);

	

		/////////////////////////////////////////////////////////////////////////

	// create the sheet

    m_pMyPropSheet = new CBibleSheet(AFX_DEVOTIONAL,pwndPropSheetHolder);


	if (!m_pMyPropSheet->Create(pwndPropSheetHolder, 
		WS_CHILD| WS_VISIBLE , 0))
	{
		delete m_pMyPropSheet;
		m_pMyPropSheet = NULL;

		return TRUE;
	}

	
	isSheet = TRUE;			// The Bible property sheet has been created
	
	// fit the property sheet into the place holder window, and show it
	CRect rectHolder;
	CRect rectSheet;
	pwndPropSheetHolder->GetWindowRect(rectHolder);
	m_pMyPropSheet ->GetWindowRect(rectSheet);

	
	
	if( ::IsWindow(m_pMyPropSheet ->GetSafeHwnd()) &&
		::IsWindow(pwndPropSheetHolder ->GetSafeHwnd())    )

		m_pMyPropSheet ->ScaleSheet(rectHolder.Height() - rectSheet.Height(),
									rectHolder.Width() - rectSheet.Width());
      
	
	
	  SetWindowPos(NULL,100,100, 750,650, SWP_NOZORDER | SWP_NOACTIVATE);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}





void CDevotional::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
	if(cx < 50 || cy < 50) return;

	// TODO: Add your message handler code here

	if(isSheet == FALSE) return;  // return if propertysheet has not been created yet

	CWnd* pwndPropSheetHolder = GetDlgItem(IDC_PLACEHOLDER_DEVOTIONAL);

	if(::IsWindow(pwndPropSheetHolder->GetSafeHwnd())) {
		pwndPropSheetHolder ->SetWindowPos(NULL,0,0,cx,cy ,SWP_NOZORDER | SWP_NOACTIVATE);

		

	CRect rectHolder;
	CRect rectSheet;
	pwndPropSheetHolder->GetWindowRect(rectHolder);
	m_pMyPropSheet ->GetWindowRect(rectSheet);
	m_pMyPropSheet ->ScaleSheet(rectHolder.Height() - rectSheet.Height(),
					rectHolder.Width() - rectSheet.Width());
}




}



